from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, Enum
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship

from app.db.session import Base
from app.models.article_tag import article_tag

class Article(Base):
    __tablename__ = "articles"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    title = Column(String(255), nullable=False)
    content = Column(Text, nullable=False)
    author_id = Column(Integer, nullable=False)
    created_at = Column(DateTime, server_default=func.now())
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
    status = Column(Enum('draft', 'published', name='article_status'), default='draft')
    view_count = Column(Integer, default=0)
    is_deleted = Column(Boolean, default=False)
    
    # 与标签的多对多关系
    tags = relationship("Tag", secondary=article_tag, back_populates="articles") 